﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using websoniBO;

namespace websoni.Adminpages
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        Album a = new Album();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnupdate.Visible = false;
                DataTable dt = a.GetRecords(-99, "", "", false, " and ");
                DataList1.DataSource = dt;
                DataList1.DataBind();
            }

        }

        protected void btnok_Click(object sender, EventArgs e)
        {
            a.alid= -99;
            a.album_name = tbalbum.Text;
            if (uploadfront.HasFile)
                uploadfront.PostedFile.SaveAs(Server.MapPath("~/images/" + uploadfront.FileName));
            a.front = uploadfront.FileName;
            a.isdeleted = false;
            a.SaveRecords();
            Response.Redirect("~/Adminpages/AAlbum.aspx");
        }

        protected void btnedit_Command(object sender, CommandEventArgs e)
        {
            btnupdate.Visible = true; btnok.Visible = false;
            tbfront.Visible = true; Label3.Visible = true;
            DataTable dte = a.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", false, " and ");
            tbalid.Text = dte.Rows[0]["alid"].ToString();
            tbalbum.Text = dte.Rows[0]["album_name"].ToString();
            tbfront.Text = dte.Rows[0]["front"].ToString();
        }

        protected void btndelete_Command(object sender, CommandEventArgs e)
        {
            DataTable dtd = a.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", false, " and ");
            a.alid = Convert.ToInt64(dtd.Rows[0]["alid"].ToString());
            a.album_name = dtd.Rows[0]["album_name"].ToString();
            a.front = dtd.Rows[0]["front"].ToString();
            a.isdeleted = true;
            a.SaveRecords();
            Response.Redirect("~/Adminpages/AAlbum.aspx");
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            a.alid =Convert.ToInt64(tbalid.Text);
            a.album_name = tbalbum.Text;
            if (uploadfront.HasFile)
            {
                uploadfront.PostedFile.SaveAs(Server.MapPath("~/images/" + uploadfront.FileName));
                a.front = uploadfront.FileName;
            }
            else
                a.front = tbfront.Text;
            a.isdeleted = false;
            a.SaveRecords();
            Response.Redirect("~/Adminpages/AAlbum.aspx");
        }
    }
}
